using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Ent.Voice.Nomination;
using Ent.Web.WebControl;
using Ent.Web.Helper;
public partial class Controls_DashEntry : DashEntry
{
    public Controls_DashEntry()
    {
        this.PreRender += new EventHandler(Controls_DashEntry_PreRender);
    }

    void Controls_DashEntry_PreRender(object sender, EventArgs e)
    {
        SetControl();
    }
    private void SetControl()
    {
        lblUser.Text = "";
        lblControls.Text = "";
        tabEntry.Width = StringHelper.ConvertUnitToString(Width);
        tabEntry.Height = StringHelper.ConvertUnitToString(Height);
        tabEntry.Style.Add(HtmlTextWriterStyle.BorderColor, BorderColor);
        tabEntry.Style.Add(HtmlTextWriterStyle.BorderStyle, BorderStyle.ToString());
        tabEntry.Style.Add(HtmlTextWriterStyle.BorderWidth, BorderWidth);
        if (BackgroundColor != System.Drawing.Color.Transparent)
            tabEntry.BgColor = BackgroundColor.ToString();

        if (ShowSeperator)
        {
            tdTitle.Style.Add("border-bottom", "solid 1px " + BorderColor);
            tdUser.Style.Add("border-top", "solid 1px " + BorderColor);
        }

        tdTitle.Height = StringHelper.ConvertUnitToString(TitleCellHeight);
        tdTitle.Align = TitleTextAlign.ToString();
        if (HeaderClass != null && HeaderClass != "")
            tdTitle.Attributes.Add("class", HeaderClass);
        tdTitle.BgColor = StringHelper.ConvertColorToHexString(TitleBackgroundColor);
        lblTitle.Font.Size = TitleFontSize;
        //if (Mode != EntryMode.TopBottom)
        string order = "";
        if (OrderBy != -1)
            order = "&o=" + OrderBy.ToString();
        lblTitle.Text = Common.GetImageTextLink("ShowEntry.aspx?id=" + Entry.Id.ToString() + order, "Images/dj/entry.gif", StringHelper.RestrictMaxChar(Entry.Title, TitleMaxChar), 15, new string[] { "c" });
        tdUser.Height = StringHelper.ConvertUnitToString(UserCellHeight);
        tdUser.Align = UserTextAlign.ToString();
        if (FooterClass != null && FooterClass != "")
            tdUser.Attributes.Add("class", FooterClass);
        tdUser.BgColor = StringHelper.ConvertColorToHexString(DetailsBackgroundColor);
        tdDetails.BgColor = StringHelper.ConvertColorToHexString(DetailsBackgroundColor);
        lblUser.Font.Size = UserFontSize;
        tdDetails.Align = UserTextAlign.ToString();
        if (BodyClass != null && BodyClass != "")
            tdDetails.Attributes.Add("class", BodyClass);
        if (Mode != EntryMode.TopBottom)
        {
            cEntryStats.Entry = Entry;
            //lblDetails.Text += Common.GetEntryStats(Entry, UserMaxChar);
            tdTitle.Style.Add(HtmlTextWriterStyle.PaddingLeft, "5px");
            tdEntry.Style.Add(HtmlTextWriterStyle.PaddingLeft, "5px");
        }
        lblUser.Text = Common.GetImageTextLink("ShowUser.aspx?id=" + Entry.Nominee.UserID, "Images/dj/user.gif", StringHelper.RestrictMaxChar(Entry.Nominee.FName + " " + Entry.Nominee.LName, UserMaxChar), 15);
        tdEntry.Align = EntryTextAlign.ToString();
        switch (Mode)
        {
            case EntryMode.TopBottom:
                tdDetails.Visible = false;
                tdUser.Controls.Add(lblUser);
                break;
            case EntryMode.TopLeft:
                tdUser.Visible = false;
                tdTitle.ColSpan = 2;
                break;
            case EntryMode.Top:
                tdDetails.Visible = false;
                tdUser.Visible = false;
                break;
            case EntryMode.Left:
                tdTitle.Visible = false;
                tdUser.Visible = false;
                tdDetails.Controls.Add(lblTitle);
                tdDetails.Controls.Add(lblUser);
                break;
            case EntryMode.HomePage:
                tdTitle.Visible = true;
                tdUser.Visible = false;
                tdTitle.Controls.Add(lblUser);
                lblUser.Text = "";
                lblControls.Text = "<span title=\"" + (Entry.Status == EntryStatus.Suspend ? ResourceHelper.Get("LBL_Suspended") : ResourceHelper.Get("LBL_Live")) + "\">" + (Entry.Status == EntryStatus.Suspend ? ResourceHelper.Get("LBL_Suspended") : ResourceHelper.Get("LBL_Live")) + "</span>";
                break;
            case EntryMode.Search:
                tdTitle.Visible = true;
                EntryMaxChar = 100;
                lblControls.Text = "<span title=\"" + (Entry.Status == EntryStatus.Suspend ? ResourceHelper.Get("LBL_Suspended") : ResourceHelper.Get("LBL_Live")) + "\">" + (Entry.Status == EntryStatus.Suspend ? ResourceHelper.Get("LBL_Suspended") : ResourceHelper.Get("LBL_Live")) + "</span>";
                break;
        }
        if ((Entry.OrganiserId != null && Session["USERID"] != null && Entry.OrganiserId.ToLower() == Session["USERID"].ToString().ToLower()) || Common.IsAdminSession)
        {
            lblControls.Text += "&nbsp;<img alt=\"" + ResourceHelper.Get("LBL_Set") + " " +
                (Entry.Status != EntryStatus.Suspend ? ResourceHelper.Get("LBL_Suspended") : ResourceHelper.Get("LBL_Live")) +
                "\" title=\"" + ResourceHelper.Get("LBL_Set") + " " +
                (Entry.Status != EntryStatus.Suspend ? ResourceHelper.Get("LBL_Suspended") : ResourceHelper.Get("LBL_Live")) +
                "\" src=\"" + ConfigurationManager.AppSettings["BaseUrl"] + "/" +
                (Entry.Status != EntryStatus.Suspend ? "images/dj/err.gif" : "images/dj/success.gif") +
                "\" class=\"de_control\" onclick=\"javascript:document.getElementById('" +
                hfEntryId.ClientID + "').value='" + Entry.Id + "'; __doPostBack('" +
                btnSuspend.UniqueID + "','')\" />";

            if (SuspendHeaderClass != null && SuspendHeaderClass != "" && Entry.Status == EntryStatus.Suspend)
                tdTitle.Attributes.Add("class", SuspendHeaderClass);
            else if (LiveHeaderClass != null && LiveHeaderClass != "" && Entry.Status == EntryStatus.Live)
                tdTitle.Attributes.Add("class", LiveHeaderClass);
        }
        if (Entry.Nominee != null && Session["USERID"] != null && Entry.Nominee.UserID.ToLower() == Session["USERID"].ToString().ToLower())
            lblControls.Text += "&nbsp;<img alt=\"" + ResourceHelper.Get("LBL_Edit") + "\" title=\"" + ResourceHelper.Get("LBL_Edit") + "\" src=\"" + ConfigurationManager.AppSettings["BaseUrl"] + "/images/dj/pen.gif\" class=\"de_control\" onclick=\"javascript:window.location.href='" + ConfigurationManager.AppSettings["BaseUrl"] + "/UpdateEntry.aspx?id=" + Entry.Id + "'\" />";
        Label lbl = new Label();
        lbl.Text = FileHelper.GetUploadString(Entry, this, Server.MapPath("~"), ConfigurationManager.AppSettings["BaseUrl"], ResourceHelper.Get("LBL_Comments"));
        pnlEntry.Controls.Add(lbl);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        btnSuspend.Style.Add(HtmlTextWriterStyle.Display, "none");
    }

    protected void btnSuspend_Click(object sender, EventArgs e)
    {
        int id = -1;
        int.TryParse(hfEntryId.Value, out id);
        if (id != -1)
        {
            Entry en = Entry.GetEntry(id);
            if ((en.OrganiserId != null && Session["USERID"] != null && en.OrganiserId.ToLower() == Session["USERID"].ToString().ToLower()) || Common.IsAdminSession)
            {
                Entry.ToggleStatus(id);
                this.Entry.Status = (this.Entry.Status == EntryStatus.Suspend ? EntryStatus.Live : EntryStatus.Suspend);
            }
        }
    }
}
